from common import *
from extra.graphics import *

default_data = {'title':'Window','size':(100,100)}

def setup(data = default_data):
    import wx
    dlg = wx.TextEntryDialog(
        None, 'Title',
        'Configure Process', str(data['title']))
    if dlg.ShowModal() == wx.ID_OK:
        data['title'] = dlg.GetValue()
    dlg.Destroy()

    dlg = wx.TextEntryDialog(
        None, 'Input size (width, height)',
        'Configure Process', str(data['size']))
    if dlg.ShowModal() == wx.ID_OK:
        try:
            data['size'] = eval(dlg.GetValue())
        except:
            pass
    dlg.Destroy()
    return data

def PixMapWindowFunc(in0 , data = default_data):

    width,height = data['size']
    win = GraphWin(data['title'], width, height)

    while True:

        matrix = in0()

        size_y = len(matrix)
        size_x = len(matrix[0])

        try:
            max = matrix.max()
        except:
            max = 255
        
        y = 0
        for yline in matrix:
            x = 0
            for val in yline:
                g = (val/max)*255
                win.plot(x,y,color_rgb(g,g,g))
                x+=1
            y+=1
        
        win.flush()
                         


